varying vec3  Normal;
varying vec3  EyeDir;
varying float Diffuse;
varying vec3  Specular;
varying vec3  Ambient;

//texture param
varying vec2 texcoord;

attribute vec2 tex;
const float specularContribution = 0.2;
const float diffuseContribution  = 1.0 - specularContribution;
//shared param
uniform vec3  lpos;
varying float LightIntensity;


void main() 
{
    gl_Position    = ftransform();
    Normal         = normalize(gl_NormalMatrix * gl_Normal);
    vec4 pos       = gl_ModelViewMatrix * gl_Vertex;
    EyeDir         = pos.xyz;
    vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
    vec3 tnorm      = normalize(gl_NormalMatrix * gl_Normal);
    vec3 lightVec   = normalize(lpos - ecPosition);
    vec3 reflectVec = reflect(-lightVec, tnorm);
    vec3 viewVec    = normalize(-ecPosition);
    
    float spec      = clamp(dot(reflectVec, viewVec), 0.0, 1.0);
    spec            = pow(spec, 16.0);
    Specular        = vec3(spec) * vec3(1.0, 0.941, 0.898) * 0.3;
    
    Diffuse         = max(dot(lightVec, tnorm), 0.0);
    texcoord        =tex;
    LightIntensity  = diffuseContribution * max(dot(lightVec, tnorm), 0.0)
    + specularContribution * spec;
}